﻿
DialogHelper = function () {
    var m_title = ""; 
    var m_msg = ""; 
    var m_btns = null; 
    this.dlgDiv = $("<div><p></p></div>");//这部分可根据情况自定义   
    this.set_Title = function (val) { this.m_title = val; }
    this.get_Title = function () { return this.m_title; }
    this.set_Msg = function (val) { this.m_msg = val; }
    this.get_Msg = function () { return this.m_msg; }
    this.set_Buttons = function (val) { this.m_btns = val; }
    this.get_Buttons = function () { return this.m_btns; }
    this.open = function () {
        $dlg = this.dlgDiv.clone(); //这个克隆很重要,否则反复添加正文。
        $dlg.children().filter("p").html(this.dlgDiv.children().filter("p").html() + this.get_Msg()); //增加自定义消息
        $dlg.dialog({
            autoOpen: true,
            show: 'blind',
            //hide: 'explode',
            position: 'center',
            height: 160,
            width: 460,
            resizable: false,
            modal: true,
            title: this.get_Title(),
            buttons: this.get_Buttons()
        });
    }
}

function MessageShow(type, title, msg) {
    dlgHelper = new DialogHelper();
    dlgHelper.set_Title(title);
    dlgHelper.set_Msg(msg);
    dlgHelper.set_Buttons({
        '确定': function (ev) {
            $(this).dialog('close');
        }
    });
    dlgHelper.open();
}

function changeimg() {
    $("#chkimg").attr("src", "/Account/GetValidateCode?t=" + Math.random(1000));
}

function showMessage(msgType, msgTitle, message) {
    initDialog(msgTitle);
    $("#divGlobalDialog").data("msg", message).dialog('open');
}

function initDialog(title) {
    $("#divGlobalDialog").dialog({
        title: title,
        width: 500,
        autoOpen: false,
        position: "top",
        modal: true,
        closeOnEscape: true,
        draggable: true,
        open: function (event, ui) {
            loadExceptionAction($(this).data("msg"));
        },
        buttons: [
            {
                text: "关闭",
                click: function () {
                    $(this).dialog('close');
                }
            }
        ]
    });
}

function loadExceptionAction(errMsg) {
    $.get('/Dialog/PartialShowException', { errMsg: errMsg, errTitle: '' },
        function (data) {
            $("#divGlobalDialog").html(data);
        }
    );
}


function initDialogConfirm() {
    $("#divConfirmDialog").dialog({
        title: "确认对话框",
        width: 400,
        autoOpen: false,
        position: "top",
        modal: true,
        closeOnEscape: true,
        draggable: true,
        open: function (event, ui) {
            $("#divConfirmDialog").html($(this).data("msg"));

        },
        buttons: [
            {
                text: "确定",
                click: function () {
                    asyncRequestExecution(
                        $(this).data("element"),
                        $(this).data("options"));
                    $(this).dialog('close');
                }
            },
            {
                text: "取消",
                click: function () {
                    $(this).dialog('close');
                }
            }
        ]
    });
}